package megrez.mail.sender.common;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Locale;
import java.util.Map;

import org.springframework.util.StringUtils;

import lombok.Data;

/**
 * 邮件消息
 * 
 * @author Lucky Yang
 * @since 0.0.1
 */
@Data
public class MailMessage {
    /** 主题 */
    private String subject;
    /** 收件人 */
    private List<String> mails = new ArrayList<>();
    /** 模板代码 */
    private String templateCode;
    /** 区域 */
    private Locale locale;
    /** 参数 */
    private Map<String, String> paramters = new HashMap<>();

    public MailMessage addParam(String key, String value) {
        paramters.put(key, value);
        return this;
    }

    public MailMessage addMail(String mail) {
        if (StringUtils.hasText(mail)) {
            mails.add(mail);
        }
        return this;
    }

    public void validate() {
        if (mails == null || mails.isEmpty()) {
            throw new IllegalArgumentException("Mail address list is empty");
        }
    }
}
